package coms.ejb.sessionbean;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import coms.dataaccess.DAOFactory;
import coms.dataaccess.ReviewDao;
//import coms.datatransfer.AssignedReviewDTO;
import coms.datatransfer.FileItemDTO;
import coms.datatransfer.ReviewDTO;

@Stateless(name = "ReviewBean", mappedName = "ReviewBean")
@Remote(ReviewBeanRemote.class)
public class ReviewBean implements ReviewBeanRemote {

	private ReviewDao reviewDAO = null;
	
	public ReviewBean(){}
	
    public void ejbCreate() {
    	reviewDAO = DAOFactory.getInstance().getReviewDAO();
    }
	
	public void createOrUpdateReview(ReviewDTO review) {
		reviewDAO.createOrUpdate(review);
	}

	public List<ReviewDTO> displayAllReview() {
		return reviewDAO.displayAll();
	}

	@Override
	public List<ReviewDTO> displayReviewedFiles(int userID) {
		return reviewDAO.displayReviewedFile(userID);
	}

	@Override
	public List<FileItemDTO> displayAssignedFiles(int userID) {
		
	List<FileItemDTO> temp = new ArrayList<FileItemDTO>();	
	List<Object[]> assignedReview = reviewDAO.displayAssignedFile(userID);
		
      for (Object[] a : assignedReview){		
			FileItemDTO file = (FileItemDTO)a[0];
			temp.add(file);		
		}
		return temp;
	}

	@Override
	public List<ReviewDTO> findByFileId(int fileID) {
		// TODO Auto-generated method stub
		return reviewDAO.findByFileId(fileID);
	}

	@Override
	public ReviewDTO displayReviewByFileAndUser(Integer fileID, Integer userID) {
		// TODO Auto-generated method stub
		return reviewDAO.displayReviewByFileAndUser(fileID, userID);
	}
}
